package map;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class MapDemo2 {
    public static void main(String[] args) {
        Map<String,Integer> map = new HashMap<>();

        map.put("语文",90);
        map.put("数学",91);
        map.put("英语",92);
        map.put("物理",93);
        map.put("化学",94);
        System.out.println("map的内容" + map);


        System.out.println("-----------------遍历key----------------");
        Set<String> set = map.keySet();
//        for (String key : set){
//            System.out.println("key"+key);
//        }
        set.forEach(str-> System.out.println("Key:"+str));


        System.out.println("-----------------遍历key和value----------------");
        Set<Map.Entry<String,Integer>> entrySet = map.entrySet();
        for(Map.Entry<String,Integer> e : entrySet){
            String key = e.getKey();
            Integer value = e.getValue();
            System.out.println("key:"+key+",value:"+value);
        }

        map.forEach((k,v)-> System.out.println(k+":"+v));

        System.out.println("-----------------遍历value----------------");
        Collection<Integer> values = map.values();
        values.forEach(v-> System.out.println("value:"+v));
    }
}
